﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;

//Tal
namespace InformationExtraction
{
    class OccupationProcess : ExtractorProcess
    {
        public override void Execute(Person person, Page page)
        {
            Regex regex = new Regex(@"(is|was)/\S+ (a|an)/\S+ (\S+/JJ )*((\S+)/NN, )*(\S+)/NN( and/\S+ (\S+)/NN)?");
            MatchCollection mc = regex.Matches(page.RawContent);
            //bool start = false;

            if (page.Title.Contains("Tupac"))
            {
                foreach (string occ in person.Occupation)
                {
                    Debug.WriteLine(occ);
                }
            }

            for (int i = 0; i < mc.Count; i++)
            {
                for (int j = 3; j < mc[i].Groups.Count; j++) //skip the first two groups
                {
                    string occ = mc[i].Groups[j].Value;
                    if (Regex.IsMatch(occ, @"^\S+$")) //&& start
                        person.Occupation.Add(occ);
                    /*if (mc[i].Value == "")
                        start = true;*/
                }
                if (person.Occupation.Count > 0)
                    break;
            }
            if (page.Title.Contains("Rabin"))
            {
                foreach (string occ in person.Occupation)
                {
                    Debug.WriteLine(occ);
                }
            }
        }
    }
}
